$(document).ready(function(){
    var $content=$('#content');
    $content.find('ul.gallery').wl_Gallery();
    parent.$.fancybox.close();
    $content.find('ul.gallery').wl_Gallery({
        group: 'wl_gallery',
        editBtn: true,
        deleteBtn: true,
        fancybox: {},
        onEdit: function (element, href, title) {
            var array = title.split("_");
            var id = array[0];
            var title = array[1];
            if(href){
                $.fancybox({
                    'transitionIn' : 'elastic',
                    'titleShow' : false,
                    'transitionOut' : 'elastic',
                    'speedIn' : 600, 
                    'speedOut' : 200, 
                    'overlayShow' :	true,
                    'type' : 'iframe',
                    'width' : '90%',
                    'height' : '90%',
                    'href' : 'http://pixlr.com/express/?referrer=LNCMS&method=GET&loc=pt-br&method=POST&image='+escape(href)+'&title='+escape(title)+'&exit='+base_cms+'imagens/imagem/consultar&target='+base_cms+'imagens/imagem/save/'+escape(id)
                });
            }
        },
        onMove: function (element, href, title, newOrder) {
            console.log(element, href, title, newOrder);
        },
        onDelete: function (element, href, title) {
            var array = title.split("_");
            var id = array[0];
            if(href){
                $.confirm(language.gallery.deletes,function(){
                    element.fadeOut();
                    $.ajax({
                        url: base_cms+"imagens/imagem/remover",
                        type: "POST",
                        data: {
                            'id' : id
                        },
                        dataType: "json",
                        beforeSend: function(){
                        //$(obj).addClass('load');
                        },
                        success: function(data) {
                            if(data.cod == 999){
                                $.msg(data.msg,{
                                    header:data.header,
                                    live:10000
                                });
                            } 
                            $.msg(data.msg,{
                                header:data.header,
                                live:10000
                            });
                        }
                    });
                });
            }
        }        
    });
    
    $("[rel$='fancybox']").fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'speedIn'   :	600, 
        'speedOut'  : 200, 
        'overlayShow' : true,
        'type'      : 'iframe',
        'width'     : '90%',
        'height'    : '90%'
    }); 
});